﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Tab2Sql
{
    /// <summary>
    /// Form allowing user to input a number and a criteria (via dropdown). They input "6" and "more than" and
    /// all lines with more than 6 delimiter matches are deleted. This allows rogue lines to be removed for large
    /// datasets.
    /// </summary>
    public partial class dialogBoxDelimiterQuery : Form
    {
        /// <summary>
        /// Called by parent to close form once we're done.
        /// </summary>
        public void RemoteClose ()
        {
            this.Close ();
        }
        /// <summary>
        /// Number that forms basis of any comparison - this is input by the user.
        /// </summary>
        public int DelimiterCount;
        /// <summary>
        ///
        /// </summary>
        public enum Criteria
        {
            /// <summary>
            /// the criteria for lines with a specific number of delimiter matches/instances.
            /// </summary>
            Exactly,
            /// <summary>
            /// the criteria with more than a given number of delimiter matches/instances.
            /// </summary>
            MoreThan,
            /// <summary>
            /// the criteria for lines with less than a given number of delimiter matches/instances.
            /// </summary>
            LessThan
        }

        /// <summary>
        /// Do we want to delete lines which are equal/more or less to supplied amount?
        /// </summary>
        public Criteria DelimiterCriteria;

        MainForm theParent;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="parent">
        /// A <see cref="MainForm"/>
        /// </param>
        public dialogBoxDelimiterQuery(MainForm parent)
        {
            theParent = parent;
            InitializeComponent();
            DelimiterCount=0;
            DelimiterCriteria = Criteria.MoreThan;
        }

        private void button1_Click(object sender, EventArgs e)
        {
        
            DelimiterCount = Convert.ToInt32(delimiterNumber.Value);
            if (delimiterCriteria.Text == "Exactly") { DelimiterCriteria = Criteria.Exactly; }
            if (delimiterCriteria.Text == "More than") { DelimiterCriteria = Criteria.MoreThan; }
            if (delimiterCriteria.Text == "Less than") { DelimiterCriteria = Criteria.LessThan; }
            theParent.Show();
            this.Close();
            


        }

        private void refreshLabel(object sender, EventArgs e)
        {
            label2.Text = delimiterCriteria.SelectedItem.ToString();
            label2.Refresh();
        }
    }
}
